﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace syh876.com.Controllers
{
    public class BaseController : Controller
    {
        #region 所有Action执行之前执行，验证是否登陆
        /// <summary>
        /// 验证是否登陆早action执行之前 执行
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //base.OnActionExecuting(filterContext);
            //if (IdentityHelper.AdminUser == null)
            //{
            //    filterContext.HttpContext.Response.Redirect("/Admin");
            //}
            //else
            //{
            //    if (!IdentityHelper.AdminUser.LoginResult)
            //    {
            //        filterContext.HttpContext.Response.Redirect("/Admin");
            //    }
            //}
        }
        #endregion

        #region 记录错误日志
        protected override void OnException(ExceptionContext filterContext)
        {
            //Exception ex = filterContext.Exception;
            //StringBuilder sb = new StringBuilder();

            //sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
            //if (filterContext.HttpContext.Request.UrlReferrer != null)
            //{
            //    sb.AppendLine("前置路径：" + filterContext.HttpContext.Request.UrlReferrer.AbsoluteUri);
            //}
            //sb.AppendLine("路径：" + filterContext.HttpContext.Request.Url.AbsoluteUri);
            //sb.AppendLine("异常：" + ex.Message);
            //sb.AppendLine("追踪：" + ex.StackTrace);
            //sb.AppendLine("============================================");
            //SYH.Utils.LoggerHelper.Write(sb.ToString());
            //filterContext.ExceptionHandled = true;
            //filterContext.Result = new RedirectResult("/Error");
        }
        #endregion

    }
}
